package com.wanghaixin.controller;

import com.wanghaixin.dto.DataGridResult;
import com.wanghaixin.dto.QueryDTO;
import com.wanghaixin.pojo.CarMake;
import com.wanghaixin.service.CarMakeService;
import com.wanghaixin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: 王海新
 * @Date: 2020/11/2 08:29
 * @Description: 品牌管理表现层
 */
@Controller
public class CarMakeController {

    @Autowired
    private CarMakeService carMakeService;

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  8:30  2020/11/2
     * @Version:  1.0.0
     * @Description:  分页查询
     */
    @RequestMapping("/sys/make/list")
    //不添加下面注解会报一下错误
    //Error resolving template [sys/make/list], template might not exist or might not be accessible by any of the configured Template Resolvers
    @ResponseBody
    public DataGridResult findByPage(QueryDTO queryDTO){
        return carMakeService.findByPage(queryDTO);
    }

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  8:34  2020/11/2
 * @Version:  1.0.0
 * @Description:  删除
 */
@RequestMapping("/sys/make/del")
    @ResponseBody
    public R delMake(@RequestBody List<Integer> ids){
    for (Integer id : ids) {
        carMakeService.delCarMake(id);
    }
    return R.ok();
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  8:38  2020/11/2
 * @Version:  1.0.0
 * @Description:  id查询
 */
@RequestMapping("/sys/make/info/{id}")
@ResponseBody
public R findById(@PathVariable("id") Integer id){
    CarMake carMake = carMakeService.finfById(id);
    return R.ok().put("make",carMake);
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  8:41  2020/11/2
 * @Version:  1.0.0
 * @Description:  添加方法
 */
@RequestMapping("/sys/make/save")
@ResponseBody
public R addCarMake(@RequestBody CarMake carMake){
    int i = carMakeService.addCarMake(carMake);
    return i>0 ? R.ok():R.error("添加失败");
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  8:44  2020/11/2
 * @Version:  1.0.0
 * @Description:  修改方法
 */
@RequestMapping("/sys/make/update")
@ResponseBody
public R upCarMake(@RequestBody CarMake carMake){
    int i = carMakeService.updateCarMake(carMake);
    return i>0 ? R.ok():R.error("修改失败");

}


/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  8:48  2020/11/2
 * @Version:  1.0.0
 * @Description:  查询所有，其它页面需要用到，在其他的service中调用
 */
}
